﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using APNotifications.Dialog;

namespace APNotifications
{
    public partial class frmSummary : Form
    {

        #region Private Properties

        private Point start_point = new Point(0, 0);
        private bool drag = false;
        private bool draggable = true;
        private string exclude_list = "";

        #endregion

        #region Public Properties

        public string ExcludeList
        {
            set
            {
                this.exclude_list = value;
            }
            get
            {
                return this.exclude_list.Trim();
            }
        }

        public bool Draggable
        {
            set
            {
                this.draggable = value;
            }
            get
            {
                return this.draggable;
            }
        }

        #endregion        

        #region Overriden Functions

        protected override void OnControlAdded(ControlEventArgs e)
        {            
            if (this.Draggable && (this.ExcludeList.IndexOf(e.Control.Name) == -1))
            {
                e.Control.MouseDown += new MouseEventHandler(Form_MouseDown);
                e.Control.MouseUp += new MouseEventHandler(Form_MouseUp);
                e.Control.MouseMove += new MouseEventHandler(Form_MouseMove);
            }
            base.OnControlAdded(e);
        }

        #endregion

        #region Public Methods

        public frmSummary()
        {
            InitializeComponent();

            this.MouseDown += new MouseEventHandler(Form_MouseDown);
            this.MouseUp += new MouseEventHandler(Form_MouseUp);
            this.MouseMove += new MouseEventHandler(Form_MouseMove);
        }

        public void bindNotifications(int Message, int Pokes, int Friends, int Invites)
        {
            label1.Text = "Messages  (" + Message.ToString() + ")";
            label2.Text = "Pokes  (" + Pokes.ToString() + ")";
            label3.Text = "Friend Requests  (" + Friends.ToString() + ")";
            label4.Text = "Invites  (" + Invites.ToString() + ")";
        }

        #endregion        

        #region Event Handlers

        private void closeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Hide();
        }

        void Form_MouseDown(object sender, MouseEventArgs e)
        {            
            this.drag = true;
            this.start_point = new Point(e.X, e.Y);
        }

        void Form_MouseUp(object sender, MouseEventArgs e)
        {
            this.drag = false;
        }

        void Form_MouseMove(object sender, MouseEventArgs e)
        {
            if (this.drag)
            {
                Point p1 = new Point(e.X, e.Y);
                Point p2 = this.PointToScreen(p1);
                Point p3 = new Point(p2.X - this.start_point.X,
                                     p2.Y - this.start_point.Y);
                this.Location = p3;
            }
        }

        private void toolStripMenuItem1_Click(object sender, EventArgs e)
        {
            frmTransparency _frmTransparency = new frmTransparency();
            _frmTransparency.ShowDialog(this);
        }

        #endregion

        private void frmSummary_Load(object sender, EventArgs e)
        {            
            this.Opacity = (((double)Config.Transparency() * 5) / 100);
        }

        private void frmSummary_Activated(object sender, EventArgs e)
        {
            this.Opacity = (((double)Config.Transparency() * 5) / 100);
        }
        
    }
}
